<?
require_once('ValidatorBase.php');

class NumberRangeValidator extends ValidatorBase {
	private $min,$max;

	// ACCESSORS
	public function setMin($value) { $this->min= 0+$value; return $this; }
	public function getMin() { return $this->min; }
	private function validateMin($number) {
		if (is_null($this->min)) return true;
		return $number>= $this->min;
	}

	public function setMax($value) { $this->max= 0+$value; return $this; }
	public function getMax() { return $this->max; }
	private function validateMax($number) {
		if (is_null($this->max)) return true;
		return $number<= $this->max;
	}

	protected function doValidate($value) {
		if (
			!is_numeric($value) ||
			!$this->validateMin($value) ||
			!$this->validateMax($value)
		) {
			throw new ValidatorException($this,$value);
		}
	}
}
